import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 62536
 * Date: 2024-03-07
 * Time: 22:32
 */
public class Test {
    public static void main(String[] args) {



    }


    public static List<List<String>> groupAnagrams(String[] strs) {

        Map<String,List<String>> map = new HashMap<>();

        for(String str: strs){
            char[] arr = str.toCharArray();
            Arrays.sort(arr);
            String str2 = Arrays.toString(arr);
            if(map.containsKey(str2)){
                map.get(str2).add(str);

            } else {
                List<String> list = new ArrayList<>();
                list.add(str);
                map.put(str2, list);
            }
        }

        List<List<String>> list = new ArrayList<>(map.values());

        return list;


    }
}
